package dw.fastfile.business.service;

import dw.fastfile.common.dto.query.AbstractPageAble;
import dw.fastfile.business.dto.Dog;
import dw.fastfile.business.dto.DogQuery;
import dw.fastfile.common.util.SqlUtil;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Set;

/**
 * @description:
 * @author: wanghao
 * @create: 2023-05-04 11:22
 **/
@Service
public class DogPageService extends AbstractPageAble<DogQuery, Dog> {

    @Override
    protected StringBuilder listSql(DogQuery dogQuery, List<Object> params) {
        StringBuilder sql = new StringBuilder("select * from chinasoftinc_db.pm_orgsheet_view s where 1=1 ");
        if (null == dogQuery) {
            return sql;
        }
        if (StringUtils.isNotBlank(dogQuery.getName())) {
            sql.append(" and s.orgName like ?");
            params.add("%" + dogQuery.getName() + "%");
        }
        if (null != dogQuery.getBeginAge()) {
            sql.append(" and s.age >= ?");
            params.add(dogQuery.getBeginAge());
        }
        if (null != dogQuery.getEndAge()) {
            sql.append(" and s.age < ?");
            params.add(dogQuery.getEndAge());
        }

        Set<Integer> types = dogQuery.getTypes();
        if (null != types && !types.isEmpty()) {
            sql.append(" and s.type in ?");
            params.add(SqlUtil.getInSql(types));
        }
        return sql;
    }
}
